package dict

import (
	"context"
	"fmt"
	model "service/model/hr"
	"service/model/mod"

	gpb "gitee.com/cloudapex/protos/hr/pb"

	"gitee.com/cloudapex/ulern/htp"
	"github.com/gin-gonic/gin"
)

/*
 * 描述: 组织架构列表(联动)(传入上级Id得到下级列表)
 * 路由: /dict/frameList
 * 方法: GET
 *********************************************************************/
type FrameList struct {
	Id int64 `form:"id" json:"id" binding:"omitempty"` //组织Id(主键)
}

func (this *FrameList) Handle(c *gin.Context, ctx context.Context) htp.Response {
	user := mod.CurrUser(c)

	type rspItem struct {
		Id    int64  `json:"id"`    // 架构id
		Name  string `json:"name"`  // 名称
		Shows string `json:"shows"` // 数据可见区间
	}

	rsp, err := model.Framework.GetFrameList(ctx, &gpb.FrameworkReq{CId: user.CId, Superior: this.Id})
	if err != nil {
		return htp.RespModelErr("", err)
	}

	items := []rspItem{}
	for _, it := range rsp.FrameworkReqs {
		items = append(items, rspItem{it.Id, it.Name, fmt.Sprintf("%d", it.Shows)})
	}
	return htp.RespOK("", &struct {
		List interface{} `json:"list"`
	}{items})
}
